package top.suven.base.http.admin.user.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.suven.base.core.mybatis.PageData;
import top.suven.base.http.admin.user.dao.UserDataWebDao;
import top.suven.base.http.admin.user.model.UserData;
import top.suven.base.http.admin.user.service.UserDataWebService;
import top.suven.base.http.admin.user.vo.response.UserDataResponseVo;
import top.suven.base.http.enums.EnableStatusEnum;
import top.suven.base.util.utilize.BeanUtil;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**   
 * @Title: UserDataWebServiceImpl.java
 * @Description: 用户扩展信息的业务处理服务类
 * @author lixiangling
 * @date   2018/08/14 16:52:42
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
@Component("userDataWebService")
public class UserDataWebServiceImpl implements UserDataWebService{
    private final static Logger logger = LoggerFactory.getLogger(UserDataWebServiceImpl.class);
    @Autowired
    private UserDataWebDao  userDataWebDao;
    /**
     * @Title: 获取用户扩展信息分页信息
     * @Description:
     * @param userData @{Link UserData}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/14 16:52:42
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public PageData<UserDataResponseVo> getUserDataPage(UserData userData, int start, int pageSize){
        int count = userDataWebDao.countEntity(userData);
        if(count == 0){
            return new PageData<UserDataResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<UserData> userDataList = userDataWebDao.findPageEntity(userData, start, pageSize);
        if(userDataList == null || userDataList.isEmpty()){
            return new PageData<UserDataResponseVo>(Collections.EMPTY_LIST,count);
        }
        List<UserDataResponseVo> userDataResponseList = userDataList.stream().map(userDataResponse -> {
            UserDataResponseVo userDataResponseVo = new UserDataResponseVo();
            BeanUtil.copyProperties(userDataResponse, userDataResponseVo);
            return userDataResponseVo;
        }).collect(Collectors.toList());
        return new PageData<UserDataResponseVo>(userDataResponseList,count);
    }
    /**
     * @Title: 获取用户扩展信息列表信息
     * @Description:
     * @param userData @{Link UserData}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/14 16:52:42
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public List<UserData> getUserDataList(UserData userData){
        return userDataWebDao.findEntity(userData);
    }

    /**
     * @Title: 新增用户扩展信息信息
     * @Description:
     * @param userData @{Link UserData}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/14 16:52:42
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void addUserData(UserData userData){
        userDataWebDao.createEntity(userData);
    }
    /**
    * @Title: 修改用户扩展信息信息
    * @Description:
    * @param userData @{Link UserData}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/14 16:52:42
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void updUserData(UserData userData){
        userDataWebDao.updateEntity(userData);
    }
   /**
    * @Title: 获取用户扩展信息信息
    * @Description:
    * @param id @{Link Long}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/14 16:52:42
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public UserData getUserData(Long id){
        UserData userData = new UserData();
        userData.setUserId(id);
        return userDataWebDao.retrieveEntity(userData);
    }
    /**
     * @Title: 删除用户扩展信息信息
     * @Description:
     * @param ids @{Link Long[]}
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/14 16:52:42
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    public void del(Long[] ids){
        userDataWebDao.del(Arrays.asList(ids));
    }
   /**
    * @Title: 启用用户扩展信息信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/14 16:52:42
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOn(Long[] ids){
        userDataWebDao.updateEnableStatus(EnableStatusEnum.ENABLE.getIndexStr(), Arrays.asList(ids));
    }
   /**
    * @Title: 禁用用户扩展信息信息
    * @Description:
    * @param ids @{Link Long[]}
    * @return
    * @throw
    * @author lixiangling
    * @date 2018/08/14 16:52:42
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    public void turnOff(Long[] ids){
        userDataWebDao.updateEnableStatus(EnableStatusEnum.DISABLE.getIndexStr(), Arrays.asList(ids));
    }
}